<?php include "htmlBase/header.php"; ?>

<?php
include "ViewBase.php";
$id_Responsavel = $_GET["id_Responsavel"];
$Entidades = MontarHeadPHP("Despesas", true, "id_Responsavel = $id_Responsavel");

require 'Entidades/Responsavel.php';
$servicoResponsavel = new Responsavel();
$Responsavel = $servicoResponsavel->ObterPorId($id_Responsavel);

require 'Entidades/ComposicaoFamiliar.php';
$servicoComposicaoFamiliar = new ComposicaoFamiliar();
$rendaDaCasa = $servicoComposicaoFamiliar->Somar("Salario", "id_Responsavel = $id_Responsavel") + $Responsavel->Salario;
$quantidadePessoas = $servicoComposicaoFamiliar->Count("id_Responsavel = $id_Responsavel") + 1;
$rendaPercapita = $rendaDaCasa / $quantidadePessoas;

MontarHeadScript("Despesas", "Cadastro", "Cadastro", "id_Responsavel=$id_Responsavel");
?>

<div class="page">
    <div class="page-header">
        <div class="page-header-content">
            <h1><span style="padding-left:80px">Situação Econômica</span> <small>(<?php echo $Responsavel->Nome; ?>)</small></h1>
            <a href="ResponsavelPainel.php?Id=<?php echo $Responsavel->Id; ?> "class="back-button big page-back"></a>
        </div>  
        <div class="progress-bar" align="rigth">
            <div class="bar bg-color-blue" style="width: 75%"></div>
        </div>

        <br/>
        <div class="page">
            <div class="page-region">
                <div class="page-region-content">

                    <h2 style="text-align: center;">Renda</h2>

                    <table class="hovered bordered">
                        <tr>
                            <th colspan="2">Descrição da Renda</th>
                            <th>Valor</th>
                        </tr>

                        <tr>
                            <td><img src="imagens/appbar.money.white.png"/></td>
                            <td>Renda da Casa</td>
                            <td><h2 style="text-align: right;"><?php echo "R$ " . number_format($rendaDaCasa, 2, ",", "."); ?></h2></td>
                        </tr>

                        <tr>
                            <td><img src="imagens/appbar.group.white.png"/></td>
                            <td>Quantidade Pessoas</td>
                            <td><h2 style="text-align: right;"><?php echo $quantidadePessoas; ?></h2></td>
                        </tr>

                        <tr>
                            <td><img src="imagens/appbar.user.white.png"/></td>
                            <td>Renda Percapita</td>
                            <td><h2 style="text-align: right;"><?php echo "R$ " . number_format($rendaPercapita, 2, ",", "."); ?></h2></td>
                        </tr>
                    </table>

                    <br/>
                    <h2 style="text-align: center;">Despesas</h2>

                    <table class="hovered bordered">
                        <th colspan="2">Despesa</th>
                        <th>Valor</th>

                        <?php
                        if ($Entidades == null)
                        {
                            ?>
                            <tr>
                                <td colspan="8">
                                    <h3 style="text-align:center">Sem Resultado</h3>
                                </td>
                            </tr>
                            <?php
                        } else
                        {
                            foreach ($Entidades as $Despesas)
                            {
                                ?>
                                <tr onclick="Selecionar(<?php echo $Despesas->Id; ?>)">
                                    <td width="1"><input type="radio" name="RadioId" Id="<?php echo $Despesas->Id; ?>" value="<?php echo $Despesas->Id; ?>"></td>
                                    <td><?php echo $Despesas->getTipoDespesas()->Nome; ?></td>
                                    <td style="text-align: right;"><?php echo "R$ " . number_format($Despesas->Valor, 2, ",", "."); ?></td>
                                </tr>
                                <?php
                            }
                        }
                        ?>
                    </table>

                    <div class="input-control" style="margin-left: auto; margin-right: auto;">
                        <button class="standart default" onclick="Novo()">Novo</button>
                        <button class="standart" onclick="Alterar()">Alterar</button>
                        <button class="standart" onclick="Excluir()">Excluir</button>
                        <a href="ResponsavelPainel.php?Id=<?php echo $Responsavel->Id; ?>" class="button standart bg-color-lighten" style="float: right">Voltar</a>
                    </div>

                </div>
            </div>
        </div>

    </div>

    <?php include "htmlBase/footer.php"; ?>
